package com.xdf.teacher.utils;

import android.content.Context;
import android.media.AudioManager;

/**
 * Created by JavaDog on 2018-3-30.
 */

public class AudioUtil {

    private AudioManager mAudioManager;
    private static AudioUtil mInstance;

    private AudioUtil(Context context) {
        mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    }

    public synchronized static AudioUtil getInstance(Context context) {
        if (mInstance == null) {
            mInstance = new AudioUtil(context);
        }
        return mInstance;
    }

    //获取多媒体最大音量
    public int getMediaMaxVolume() {
        return mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    }

    //获取通话最大音量
    public int getCallMaxVolume() {
        return mAudioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);
    }

    //获取系统音量最大值
    public int getSystemMaxVolume() {
        return mAudioManager.getStreamMaxVolume(AudioManager.STREAM_SYSTEM);
    }

    //获取提示音量最大值
    public int getAlermMaxVolume() {
        return mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
    }

    public int getRingMaxVolume() {
        return mAudioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
    }

    /**
     * 设置多媒体音量
     * 这里我只写了多媒体和通话的音量调节，其他的只是参数不同，大家可仿照
     */
    public void setSystemVolume(int volume) {
        mAudioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, //音量类型
                volume,
                AudioManager.FLAG_PLAY_SOUND);
    }

    public void setMediaVolume(int volume) {
        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, //音量类型
                volume,
                AudioManager.FLAG_PLAY_SOUND);
    }

    public void setAlarmVolume(int volume) {
        mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, //音量类型
                volume,
                AudioManager.FLAG_PLAY_SOUND);
    }

    public void setRingVolume(int volume) {
        mAudioManager.setStreamVolume(AudioManager.STREAM_RING, //音量类型
                volume,
                AudioManager.FLAG_PLAY_SOUND);
    }


    //设置通话音量
    public void setCallVolume(int volume) {
        mAudioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,
                volume,
                AudioManager.FLAG_PLAY_SOUND);
    }
}